package com.grom.dao;

import java.util.List;

import com.grom.po.GcmsUser;
import com.grom.util.IDCreator;
import com.holder.DBContextHolder;
import com.holder.DBUTil;

public class GcmsUserDaoImpl implements GcmsUserDao {

	public List<GcmsUser> getAllUsers() {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		return DBUTil.select(GcmsUser.class);
	}

	public void add(GcmsUser user) {
		user.setID(IDCreator.getSingleId());
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.save(user);
	}

	public void update(GcmsUser user) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.update(user);
	}

	public void delete(GcmsUser user) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		DBUTil.delete(user);
	}

	public List<GcmsUser> selectByCondition(String sql) {
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		return DBUTil.getResult(sql, GcmsUser.class);
	}

	public GcmsUser getUserByID(String id) {
		String sql = "select * from gcmsuser where id='" + id + "'";
		DBContextHolder.setContextConnection(DatabaseDao.getConnection());
		List<GcmsUser> resutl = DBUTil.getResult(sql, GcmsUser.class);
		if (resutl == null || resutl.size() == 0) {
			return new GcmsUser();
		}
		return resutl.get(0);
	}

}
